package me.zhengjie.repository;

import me.zhengjie.dto.sqlServer.TaskResult;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import java.time.LocalDateTime;

public interface TaskResultRepository  extends JpaRepository<TaskResult, Integer>, JpaSpecificationExecutor<TaskResult> {

    @Query("select t from TaskResult t where t.wcsTaskType=1 and t.status !=2 and t.status !=3")
     TaskResult findInBoundTask();

    @Query("select t from TaskResult t where t.wcsTaskType=2 and t.status !=2 and t.status !=3")
    TaskResult findOutBoundTask();

    TaskResult findTaskResultByWmsTaskId(String id);

    @Modifying
    @Query("update TaskResult tr set tr.fromLocation=?1, tr.toLocation=?2, tr.status=?3,  tr.lastUpdated=?4 where tr.wmsTaskId=?5")
    void updateTaskResult(String fromLocation, String toLocation, Integer status, LocalDateTime lastUpdated, String wmsTaskId);

    TaskResult findTaskResultByWcsTaskType(Integer wcsTaskType);

    int deleteByWcsTaskType(Integer taskType);

    int deleteTaskResultByWmsTaskId(String wmsTaskId);
}
